/****************************************************************************

Force Engine v0.5

Creado: 28/03/08
Clase: Scene.h
Hecho by: German Battiston AKA Melkor

****************************************************************************/

//---------------------------------------------------------------------------
#include "Scene.h"
//---------------------------------------------------------------------------
Scene::Scene()
{
	/***/
}
//---------------------------------------------------------------------------
Scene::Scene(Graphics & rkGraphics)
:
m_pkGraphics(&rkGraphics),
m_pkInput(NULL),
m_pkCamera(NULL)
{
	m_pkCamera = new Camera(0.0f, 0.0f, -100.0f);
}
//---------------------------------------------------------------------------
bool Scene::Init(Input * pkInput)
{
	m_pkInput = pkInput;

	SortEntitiesByZ();

	return OnInit();
}
//---------------------------------------------------------------------------
bool Scene::Update(float fTimeBetweenFrames)
{
	for(unsigned int i = 0; i < m_apkEntities2D.size(),i < m_apkEntities3D.size(); i++)
	{
		m_apkEntities2D[i]->Update(fTimeBetweenFrames);
		m_apkEntities3D[i]->Update(fTimeBetweenFrames);
	}

	return OnUpdate(fTimeBetweenFrames);
}
//---------------------------------------------------------------------------
void Scene::Draw()
{
	m_pkGraphics->SetCamera(m_pkCamera);

	for(unsigned int i = 0; i < m_apkEntities2D.size(),i < m_apkEntities3D.size(); i++)
	{
		m_apkEntities2D[i]->Draw(*m_pkGraphics);
		m_apkEntities3D[i]->Draw();
	}
	
	OnDraw();
}
//---------------------------------------------------------------------------
void Scene::SortEntitiesByZ()
{
	sort(m_apkEntities2D.begin(), m_apkEntities2D.end(), Scene::Entity2DComp);
}
//---------------------------------------------------------------------------
bool Scene::Entity2DComp(Entity2D * pkEnt1, Entity2D * pkEnt2)
{
	return (pkEnt1->GetPosZ() > pkEnt2->GetPosZ());
}
//---------------------------------------------------------------------------
bool Scene::DeInit()
{
	return OnDeInit();
}
//---------------------------------------------------------------------------
Scene::~Scene()
{
	delete m_pkCamera;
	m_pkCamera = NULL;
}
//---------------------------------------------------------------------------